package tjo;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

/**
 * This test verifies that the Meteor.whichWallOrCorner method correctly identifies when the robot
 * which calls the method is near a wall or corner.
 * 
 * @author Jordan Takayama
 * @since October 10, 2011
 */
public class TestMethodWhichWallOrCorner {
  /**
   * Instantiate a copy of the class containing the method to be tested.
   */
  public tjo.Meteor testRobot = new tjo.Meteor();

  /**
   * The maximum possible x-coordinate on a sample 800 by 600 pixel battlefield.
   */
  private static final double MAX_WIDTH = 800.0;

  /**
   * The maximum possible y-coordinate on a sample 800 by 600 pixel battlefield.
   */
  private static final double MAX_HEIGHT = 600.0;

  /**
   * Represents the origin coordinates (x and y) of any Robocode battlefield.
   */
  private static final double ORIGIN = 0.0;

  /**
   * Defines the "danger zone" (in pixels) around the walls which determines if the robot is near a
   * wall or corner.
   */
  private static double outerBound = 200.0;

  /**
   * Tests all possible return values (0 to 8) for Meteor.whichWallOrCorner.
   */
  @Test
  public void test() {
    assertEquals("Check case not near any wall or corner: ", 
        testRobot.whichWallOrCorner(ORIGIN, MAX_WIDTH, MAX_HEIGHT, 300.0, 250.0, outerBound), 0);
    assertEquals("Check case near east wall: ",
        testRobot.whichWallOrCorner(ORIGIN, MAX_WIDTH, MAX_HEIGHT, 170.0, 215.0, outerBound), 1);
    assertEquals("Check case near south wall: ",
        testRobot.whichWallOrCorner(ORIGIN, MAX_WIDTH, MAX_HEIGHT, 357.0, 200.0, outerBound), 2);
    assertEquals("Check case near west wall: ",
        testRobot.whichWallOrCorner(ORIGIN, MAX_WIDTH, MAX_HEIGHT, 770.0, 320.5, outerBound), 3);
    assertEquals("Check case near north wall: ",
        testRobot.whichWallOrCorner(ORIGIN, MAX_WIDTH, MAX_HEIGHT, 300.0, 540.0, outerBound), 4);
    assertEquals("Check case near south-west corner: ",
        testRobot.whichWallOrCorner(ORIGIN, MAX_WIDTH, MAX_HEIGHT, 40.1, 30.0, outerBound), 5);
    assertEquals("Check case near south-east corner: ",
        testRobot.whichWallOrCorner(ORIGIN, MAX_WIDTH, MAX_HEIGHT, 640.0, 120.3, outerBound), 6);
    assertEquals("Check case near north-east corner: ",
        testRobot.whichWallOrCorner(ORIGIN, MAX_WIDTH, MAX_HEIGHT, 650.0, 756.0, outerBound), 7);
    assertEquals("Check case near north-west corner: ",
        testRobot.whichWallOrCorner(ORIGIN, MAX_WIDTH, MAX_HEIGHT, 42.0, 682.0, outerBound), 8);
  }
}
